Attribute VB_Name = "AddMenuItems"
Option Explicit
Option Private Module
Public Sub AddMenuItems(ByVal Target As Range)
    Dim icbc
    If Not Application.Intersect(Target, ActiveSheet.usedrange) Is Nothing Then
        '
        ' Delete icbc Control
        '
        For Each icbc In Application.CommandBars("cell").Controls
            If icbc.Tag = "brccm" Then icbc.Delete
        Next icbc

        ' used range add "Test Measure"
        With Application.CommandBars("cell").Controls.Add _
                                            (Type:=msoControlButton, before:=1, temporary:=True)
                                            .Caption = "Test Measure"
                                            .OnAction = "'" & ThisWorkbook.Name & "'!TestMeasure.TestMeasure"
                                            .Tag = "brccm"
                                            .Parameter = .Caption

        End With
        
        '
        'A column of the first measure add "Test Line" command bar
        '
        If Split(Target.address, "$")(1) = "I" Then
            With Application.CommandBars("cell").Controls.Add _
                                                (Type:=msoControlButton, before:=2, temporary:=True)
                                                .Caption = "Test Row"
                                                .OnAction = "'" & ThisWorkbook.Name & "'!TestMeasure.TestMeasure"
                                                .Tag = "brccm"
                                                .Parameter = .Caption
            End With
        End If
        
    End If
    'Debug.Print ActiveWorkbook.Name

End Sub

